import * as echarts from 'echarts';
import request from "@/api/request";
import type { Ref } from 'vue';
import { useThemeStore } from '@/stores/theme'

export function getHistogram(){
    return request({
        url:"/admin/histogram",
        method:"get"
    })
}

export function histogram(container: Ref<HTMLElement | null, HTMLElement | null>,newData: { xAxis?: any; series?: any; }) {
    const themeStore = useThemeStore()
    const textColor = themeStore.isDark ? '#ffffff' : '#303133'

    if (container.value) {
        const myChart = echarts.init(container.value);
        myChart.setOption({
            title: {
                text: 'ECharts 入门示例',
                textStyle: {
                    color: textColor
                }
            },
            tooltip: {},
            xAxis: {
                data: newData.xAxis,
                axisLabel: {
                    color: textColor
                }
            },
            yAxis: {
                axisLabel: {
                    color: textColor
                }
            },
            series: [
                {
                    name: '金额',
                    type: 'bar',
                    data: newData.series
                }
            ]
        });
    } else {
        console.error('lineChart is not available');
    }
}
